BKT Suomi


ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
  filter(
    taloustoimi == "B1GMH Bruttokansantuote markkinahintaan",
    tiedot == "Kausitasoitetun ja työpäiväkorjatun sarjan volyymin muutos vuodentakaisesta, %",
    time >= "2014-01-01"
  ) |>
  mutate(tiedot = "BKT") |>
  ptt_plot(
    grouping = tiedot,
    title = "BKT Suomi",
    subtitle = "Vuosimuutos",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |>
  ptt_plot_add_prediction(ennuste_data) |>
  ptt_plot_create_widget()
#> i Connecting to robonomistServer at ptt.robonomist.com
#> v Connecting to robonomistServer at ptt.robonomist.com [225ms]
#> 
#> i Connected successfully to robonomistServer 2.5.12
#> v Connected successfully to robonomistServer 2.5.12 [34ms]
#> 
#> \ Requesting get
#> v Requesting get [407ms]
#> 
#> Using "bkt_suomi" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Venäjän loppukysynnän osuus arvonlisästä


pdat_tiva_va <- robonomistClient::data_get("oecd/TIVA_2021_C1", tidy_time = TRUE) |> 
  filter(
    Indicator %in% c("Value added", "Domestic value added embodied in foreign final demand"),
                `Country / Region` %in% c("Finland", "Euro area (19 countries)", "China (People's Republic of)", "United States"),
                # `Partner country / region` %in% c("Russian Federation", "World"),
                Industry == "TOTAL"
         ) |> 
  collect() |> 
  mutate(value = as.numeric(value)) |> 
  statfitools::clean_names() |> 
  mutate(across(where(is.character), as_factor))
#> \ Requesting get
#> v Requesting get [94ms]
#> 
#> \ Requesting get
#> v Requesting get [149ms]
#> 

pdat_tiva_va |>
  filter_recode(
    country_region = c(
    "Suomi" = "Finland",
    "Euroalue" = "Euro area (19 countries)",
    "Kiina" = "China (People's Republic of)",
    "USA" = "United States"
    )
    # ,
    # partner_country_region = c("Russian Federation")
  ) |> 
  group_by(time, country_region) |> 
  summarise(value = 100*value[indicator == "Domestic value added embodied in foreign final demand" & 
                              partner_country_region == "Russian Federation"] /
              value[indicator == "Value added"]) |> 
  ungroup() |> 
  aplot_lines(colour = country_region,
              title = "Venäjän loppukysynnän osuus BKT:sta",
              subtitle ="%",
              source = "OECD") |>
  ptt_plot_create_widget()
#> `summarise()` has grouped output by 'time'. You can override using the
#> `.groups` argument.
#> No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
#> Using "venajan_loppukysynnan_osuus_bktsta" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

BKT USA, euroalue, Suomi


# luodaan bkt:t usa, suomi ja euroalue. indeksoidaan, perusvuodeksi 2020.

usa_bkt <-
  ptt_data_robo("fred/GDPC1") |>
  filter(time >= "2014-01-01") |>
  select(tiedot = series_id, time, value) |>
  mutate(tiedot = "USA")
#> \ Requesting get
#> v Requesting get [695ms]
#> 

suomi_bkt <-
  ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
  filter(
    taloustoimi == "B1GMH Bruttokansantuote markkinahintaan",
    tiedot == "Kausitasoitettu ja työpäiväkorjattu sarja, viitevuosi 2015, miljoonaa euroa",
    time >= "2014-01-01"
  ) |>
  select(tiedot, time, value) |>
  mutate(tiedot = "Suomi")
#> \ Requesting get
#> v Requesting get [291ms]
#> 

euroalue_bkt <-
  ptt_data_robo_l("eurostat/namq_10_gdp") |>
  filter(
    geo == "Euro area - 19 countries  (from 2015)",
    na_item == "Gross domestic product at market prices",
    s_adj == "Seasonally and calendar adjusted data",
    unit == "Chain linked volumes, index 2015=100",
    time >= "2014-01-01"
  ) |>
  select(tiedot = na_item, time, value) |>
  mutate(tiedot = "Euroalue")
#> \ Requesting get
#> | Requesting get
#> / Requesting get
#> v Requesting get [10s]
#> 

yhdistetty_bkt_data <-
  bind_rows(usa_bkt, suomi_bkt, euroalue_bkt) |>
  group_by(across(!c(time, value))) |>
  mutate(value = rebase(value, time, 2019)) |>
  ungroup()

# apufunktio indeksoinnin laskemiseen
avg_value_2021 <- function(d, sarja) {
  d |>
    filter(tiedot == sarja) |>
    filter(year(time) == 2021) |>
    pull(value) |> mean()
}

#  Muokataan ennustedata.
bkt_vertailu_ennusteet <-
  ennuste_data |>
  filter(sarja_nmi %in% c("BKT")) |>
  mutate(across(matches("[0-9]{4}"), ~ as.double(.x))) |>
  pivot_longer(cols = matches("[0-9]{4}"), names_to = "year") |>
  select(year, sarja_nmi, value) |>
  group_by(sarja_nmi) |>
  slice_tail(n = 2)

#muokataan suomen BKT ennustedata indeksoituun muotoon
ennuste_indeksoitu_2022 <- bkt_vertailu_ennusteet |>
  filter(year == "2022") |>
  mutate(value = avg_value_2021(yhdistetty_bkt_data, "Suomi") * (1 + value/100))

ennuste_indeksoitu_2023 <- bkt_vertailu_ennusteet |>
  filter(year == "2023")  |>
  mutate(value = (ennuste_indeksoitu_2022$value * (1 + value/100)))

ennusteet_suomi_bkt <- bind_rows(ennuste_indeksoitu_2022, ennuste_indeksoitu_2023) |>
  mutate(sarja_nmi = "Suomi")

# luodaan kuvaaja käyttäen yhdistettyä bkt dataa sekä muodostettua ennustedataa
yhdistetty_bkt_data|>
  ptt_plot(
    grouping = tiedot,
    title = "Bruttokansantuote",
    subtitle = "Indeksi 2019 = 100",
    caption =  "Lähde: Tilastokeskus, BEA, Eurostat ja PTT",
    rangeslider = FALSE,
    ## rangeslider = "2015-01-01",
    zeroline = F,
    hovertext =  list(rounding = 1, unit = "(indeksi 2020=100)", extra = "")
    # ,
    # axis_limits = list(y = c(89, 113))
  ) |>
  ptt_plot_add_prediction(ennusteet_suomi_bkt, custom_pred_data = TRUE) |>
  ptt_plot_create_widget()
#> No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
#> Using "bruttokansantuote" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Vienti ja tuonti

ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
  filter(
    taloustoimi %in% c("P7R Tavaroiden ja palvelujen tuonti, tulona",
                       "P6K Tavaroiden ja palvelujen vienti, menona"),
    tiedot == "Kausitasoitetun ja työpäiväkorjatun sarjan volyymin muutos vuodentakaisesta, %",
    time >= "2014-01-01"
  ) |>
  mutate(
    tiedot = recode(taloustoimi,
                    "P7R Tavaroiden ja palvelujen tuonti, tulona" = "Tuonti",
                    "P6K Tavaroiden ja palvelujen vienti, menona" = "Vienti"
                    )
  ) |>
  ptt_plot(
    grouping = tiedot,
    title = "Vienti ja tuonti",
    subtitle = "%, volyymin vuosimuutos",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 1, unit = "", extra = "")
  ) |>
  ptt_plot_add_prediction(ennuste_data) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [270ms]
#> 
#> Using "vienti_ja_tuonti" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.
ptt_data_robo("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
filter_recode(
  taloustoimi = c(
    "Tavaroiden vienti" = "P61K Tavaroiden vienti, menona",
    "Palvelujen vienti" = "P62K Palvelujen vienti, menona",
    "Tavaroiden tuonti" = "P71R Tavaroiden tuonti, tulona",
    "Palvelujen tuonti" = "P72R Palvelujen tuonti, tulona"),
  tiedot = "Kausitasoitettu ja työpäiväkorjattu sarja, viitevuosi 2015, miljoonaa euroa") |>
  filter(time >= "2019-01-01") |> 
  group_by(across(!c(time, value))) |> 
  mutate(value = rebase(value, time, 2019)) |> 
  ungroup() |> 
  ptt_plot(
    grouping = taloustoimi,
    title = "Tavaroiden ja palveluiden vienti ja tuonti",
    subtitle = "indeksi 2019 = 100, volyymi",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 1, unit = "", extra = "")
  ) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [13ms]
#> 
#> No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
#> Using "tavaroiden_ja_palveluiden_vienti_ja_tuonti" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Venäjän osuus kaupasta


ptt_data_robo("StatFin/kan/tpulk/statfin_tpulk_pxt_12gq.px") |>
  filter_recode(
    alue = c(
      RU = "Venäjä",
      YHT = "Ulkomaat yhteensä"
    ),
    tiedot = c(
      "Vienti" = "Vienti, miljoonaa euroa",
      "Tuonti" = "Alkuperämaittainen tuonti, miljoonaa euroa"
    ),
    palveluera = c(
      "GS Tavarat ja palvelut"
      # "G Tavarat",
      # "S Palvelut",
    )
  ) |> 
  filter(time >= "2014-01-01") |> 
  spread(alue, value) |> 
  mutate(value = 100 * RU / YHT) |>  
    ptt_plot(
    grouping = tiedot,
    title = "Venäjän osuus viennistä ja tuonnista",
    subtitle = "%, tavara ja palvelukaupan arvosta",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 1, unit = "", extra = "")
  ) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [204ms]
#> 
#> No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
#> Using "venajan_osuus_viennista_ja_tuonnista" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Kauppa- ja vaihtotase

ptt_data_robo_l("StatFin/kan/mata/kk/statfin_mata_pxt_12gf.px") |>
  filter(
    tiedot == "Tulojen ja menojen erotus (netto), miljoonaa euroa",
    maksutase_era %in% c("CA Vaihtotase", "G Tavarat"),
    time >= "2014-01-01"
  ) |>
  mutate(time = year(time)) |>
  with_groups(c(maksutase_era, time), filter, n() == 12) |>
  with_groups(c(maksutase_era, time), summarize, value = sum(value)/1000) |>
  mutate(
    time = make_date(time, 7),
    maksutase_era = recode(maksutase_era,
                           "CA Vaihtotase" = "Vaihtotase",
                           "G Tavarat" = "Kauppatase")
  ) |>
  ptt_plot(
    grouping = maksutase_era,
    title = "Vaihtotase ja kauppatase",
    subtitle = "Mrd. €",
    caption = "Lähde: Tilastokeskus",
    rangeslider = F,
    axis_limits = list(x = c("2014-01-01","2021-12-30")),
    hovertext =  list(dateformat="Annual", rounding = 2, unit = "Mrd. €", extra = ""),
    plot_type = c("Vaihtotase" = "bar", "Kauppatase" = "scatter")
  ) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [150ms]
#> 
#> Using "vaihtotase_ja_kauppatase" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Yksityinen kulutus

ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
  filter(
    taloustoimi == "P3KS14_S15 Yksityiset kulutusmenot, menona",
    tiedot == "Kausitasoitetun ja työpäiväkorjatun sarjan volyymin muutos vuodentakaisesta, %",
    time >= "2014-01-01"
  ) |>
  mutate(tiedot = "Yksityinen kulutus") |>
  ptt_plot(
    grouping = tiedot,
    title = "Yksityinen kulutus",
    subtitle = "Vuosimuutos",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
      zeroline = T,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |>
  ptt_plot_add_prediction(ennuste_data) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [565ms]
#> 
#> Using "yksityinen_kulutus" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Julkinen kulutus

ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
  filter(
    taloustoimi == "P3KS13 Julkiset kulutusmenot, menona",
    ## tiedot == "Kausitasoitetun ja työpäiväkorjatun sarjan volyymin muutos vuodentakaisesta, %",
    tiedot == "Trendisarjan volyymin muutos vuodentakaisesta, %",
    time >= "2014-01-01"
  ) |>
  mutate(tiedot = "Julkinen kulutus") |>
  ptt_plot(
    grouping = tiedot,
    title = "Julkinen kulutus",
    subtitle = "Vuosimuutos",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |>
  ptt_plot_add_prediction(ennuste_data) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [8ms]
#> 
#> Using "julkinen_kulutus" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Julkinen velka


ptt_data_robo_l("StatFin/jul/jyev/statfin_jyev_pxt_12sy.px") |>
  filter(
    time >= "2014-01-01",
    tiedot == "Julkisyhteisöjen EDP-velan BKT-suhde, %"
  ) |>
  mutate(tiedot = "Velkasuhde") |>
  select(tiedot, time, value) |>
  ptt_plot(
    grouping = tiedot,
    title = "Julkisyhteisöjen velka",
    subtitle = "Velan suhde BKT:hen, %",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = F,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  )  |>
  # plotly::layout(
  #   yaxis = list(range = c(55,75))
  # ) |>
  ptt_plot_add_prediction(ennuste_data) |> 
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [96ms]
#> 
#> Using "julkisyhteisojen_velka" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Julkisen sektorin tasapaino

ptt_data_robo("StatFin/jul/jtume/statfin_jtume_pxt_11zf.px") |>
  filter(
    taloustoimi == "B9  Nettoluotonanto (+)/Nettoluotonotto(-)",
    sektori %in% c(
      "S13 Julkisyhteisöt",
      "S1311 Valtionhallinto",
      "S1313 Paikallishallinto",
      "S13141 Työeläkelaitokset",
      "S13149 Muut sosiaaliturvarahastot"
    ),
    tiedot == "Suhde BKT:hen (kausitasoitettu ja työpäiväkorjattu sarja), %",
    time >= "2013-01-01"
  ) |>
  mutate(sektori = recode(
    sektori,
    "S13 Julkisyhteisöt" = "Yhteensä",
    "S1311 Valtionhallinto" = "Valtio",
    "S1313 Paikallishallinto" = "Kunnat",
    "S13141 Työeläkelaitokset" = "Sosiaaliturvarahastot",
    "S13149 Muut sosiaaliturvarahastot" = "Sosiaaliturvarahastot"
  )) |>
  with_groups(c(time, sektori), summarize, value = sum(value)) |>
  ptt_plot(
    grouping = sektori,
    title = "Julkisen sektorin tasapaino",
    subtitle = "Nettoluotonanto, % BKT:seen",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |>
  ptt_plot_add_prediction(
    ennuste_data |>
      mutate(sarja_nmi = recode(sarja_nmi,
                                "Nettoluotonanto Valtio" = "Valtio",
                                "Nettoluotonanto Paikallishallinto" = "Kunnat",
                                "Nettoluotonanto Sosiaaliturvarahastot" = "Sosiaaliturvarahastot",
                                "Nettoluotonanto Jukinen sektori" = "Yhteensä"
                                )) 
    |>
    filter(sarja_nmi == "Valtio")
  ) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [498ms]
#> 
#> Using "julkisen_sektorin_tasapaino" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Tulot ja kulutus

ptt_data_robo("StatFin/kan/vtp/statfin_vtp_pxt_11sf.px") |>
  filter(
    time >= "2014-01-01",
    taloustoimi %in% c("B6NS14 Käytettävissä oleva tulo, kotitaloudet, netto",
                       "P31NCK Yksityiset kulutusmenot, menona"),
    tiedot == "Volyymin muutokset, %"
  ) |>
  mutate(taloustoimi = recode(taloustoimi,
    "B6NS14 Käytettävissä oleva tulo, kotitaloudet, netto" = "Käytettävissä olevat tulot",
    "P31NCK Yksityiset kulutusmenot, menona" = "Yksityinen kulutus"
  )) |>
  ptt_plot(
    grouping = taloustoimi,
    title = "Tulot ja kulutus",
    subtitle = "%-muutos, reaalinen",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [152ms]
#> 
#> Using "tulot_ja_kulutus" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Investoinnit

ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
  filter(
    taloustoimi %in% c("P51K Kiinteän pääoman bruttomuodostus, menona",
                       "P51KXS13 Yksityiset investoinnit",
                       "P51KS13 Julkiset investoinnit"),
    tiedot == "Kausitasoitetun ja työpäiväkorjatun sarjan volyymin muutos vuodentakaisesta, %",
    time >= "2014-01-01"
  ) |>
  mutate(
    tiedot = recode(taloustoimi,
                    "P51K Kiinteän pääoman bruttomuodostus, menona" = "Investoinnit",
                    "P51KXS13 Yksityiset investoinnit" = "Yksityiset investoinnit",
                    "P51KS13 Julkiset investoinnit" = "Julkiset investoinnit"
                    )
  ) |>
  ptt_plot(
    grouping = tiedot,
    title = "Investoinnit",
    subtitle = "%, volyymin vuosimuutos",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |>
  ptt_plot_add_prediction(ennuste_data) |>
  ptt_plot_create_widget()##  |>
#> \ Requesting get
#> v Requesting get [257ms]
#> 
#> Using "investoinnit" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.
## ptt_plot_create_widget("investoinnit")
ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
  filter(
    taloustoimi %in% c(
      "P51K Kiinteän pääoman bruttomuodostus, menona",
      "P51KN111+N112 Rakennusinvestoinnit",
      "P51KN113+N114 Kone-, laite- ja kuljetusvälineinvestoinnit: asejärjestelmät",
      "P51KN115+N117 Kasvatettavat varat ja henkiset omaisuustuotteet"
      ),
    tiedot == "Trendisarjan volyymin muutos vuodentakaisesta, %",
    time >= "2014-01-01"
  ) |>
  mutate(
    tiedot = recode(taloustoimi,
                    "P51K Kiinteän pääoman bruttomuodostus, menona" = "Yhteensä",
                    "P51KN111+N112 Rakennusinvestoinnit" = "Rakennus",
                    "P51KN113+N114 Kone-, laite- ja kuljetusvälineinvestoinnit: asejärjestelmät" = "Kone ja laite",
                    "P51KN115+N117 Kasvatettavat varat ja henkiset omaisuustuotteet" = "Muut (aineettomat)",
                    )
  ) |>
  ptt_plot(
    grouping = tiedot,
    title = "Investoinnit",
    subtitle = "%, muutos, trendi",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |>
  ptt_plot_create_widget() ## |>
#> \ Requesting get
#> v Requesting get [10ms]
#> 
#> Using "investoinnit" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.
## ptt_plot_add_prediction(ennuste_data)## |> ## ptt_plot_create_widget("investoinnit")

Työllisyysaste

ptt_data_robo_l("StatFin/tym/tyti/kk/statfin_tyti_pxt_135z.px") |>
  filter(
    tiedot == "Työllisyysaste, 15-64-vuotiaat, %, trendi",
    time >= "2014-01-01"
  ) |>
  mutate(tiedot = "Työllisyysaste") |>
  ptt_plot(
    grouping = tiedot,
    title = "Työllisyysaste",
    subtitle = "%, trendi",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |>
  ptt_plot_add_prediction(ennuste_data) |>
  ptt_plot_create_widget()##  |>
#> \ Requesting get
#> v Requesting get [116ms]
#> 
#> Using "tyollisyysaste" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.
## ptt_plot_create_widget("")

Työttömyysaste

ptt_data_robo_l("StatFin/tym/tyti/kk/statfin_tyti_pxt_135z.px") |>
  filter(
    tiedot == "Työttömyysaste, %, trendi",
    time >= "2014-01-01"
  ) |>
  mutate(tiedot = "Työttömyysaste") |>
  ptt_plot(
    grouping = tiedot,
    title = "Työttömyysaste",
    subtitle = "%, trendi",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    hovertext =  list(rounding = 1, unit = "%", extra = "")
  ) |>
  ptt_plot_add_prediction(ennuste_data) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [13ms]
#> 
#> Using "tyottomyysaste" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Työvoima

ptt_data_robo_l("StatFin/tym/tyti/kk/statfin_tyti_pxt_135y.px") |>
  filter(
    tiedot == "Työvoima, 1000 henkilöä",
    time >= "2014-01-01",
    sukupuoli == "Yhteensä",
    ikaluokka == "15 - 74"
  ) |>
  mutate(tiedot = "Työvoima") |>
  ptt_plot(
    grouping = tiedot,
    title = "Työvoima",
    subtitle = "1000 henkilöä",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    hovertext =  list(rounding = 0, unit = "(1000 henkilöä)", extra = "")
  ) |>
  ptt_plot_add_prediction(ennuste_data, hovertext = list(rounding = 0,
        unit = "(1000 henkilöä)", extra = "(ennuste)")) |>
  ptt_plot_create_widget()  ##  |>
#> \ Requesting get
#> v Requesting get [147ms]
#> 
#> Using "tyovoima" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.
## ptt_plot_create_widget("")

Työlliset

ptt_data_robo_l("StatFin/tym/tyti/kk/statfin_tyti_pxt_135z.px") |>
  filter(
    tiedot == "Työlliset, 1000 henkilöä, trendi",
    time >= "2014-01-01"
  ) |>
  mutate(tiedot = "Työlliset") |>
  ptt_plot(
    grouping = tiedot,
    title = "Työlliset",
    subtitle = "1000 henkilöä, trendi",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    hovertext =  list(rounding = 0, unit = "(1000 henkilöä)", extra = "")
  ) |>
  ptt_plot_add_prediction(ennuste_data, hovertext = list(rounding = 0,
        unit = "(1000 henkilöä)", extra = "(ennuste)")) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [137ms]
#> 
#> Using "tyolliset" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Työlliset ja työvoima


tyovoima <-
  ptt_data_robo_l("StatFin/tym/tyti/kk/statfin_tyti_pxt_135y.px") |>
  filter(
    tiedot == "Työvoima, 1000 henkilöä",
    time >= "2014-01-01",
    sukupuoli == "Yhteensä",
    ikaluokka == "15 - 74"
  ) |>
  mutate(tiedot = "Työvoima") |>
  select(tiedot, time, value)
#> \ Requesting get
#> v Requesting get [140ms]
#> 

# Lasketaan trendi työvoimalle
tyovoima <-
  tyovoima |>
  mutate(value = statfitools::trend_series(value, time = time))

tyolliset <-
  ptt_data_robo_l("StatFin/tym/tyti/kk/statfin_tyti_pxt_135z.px") |>
  filter(
    tiedot == "Työlliset, 1000 henkilöä, trendi",
    time >= "2014-01-01"
  ) |>
  mutate(tiedot = "Työlliset")
#> \ Requesting get
#> v Requesting get [119ms]
#> 

# yhdistetään datasetit ja piirretään
bind_rows(tyovoima, tyolliset) |>
    mutate(value = value / 1000) |>
    ptt_plot(
    grouping = tiedot,
    title = "Työlliset ja työvoima",
    subtitle = "Miljoonaa, trendi",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 2, unit = "(miljoonaa henkilöä)", extra = "")
  ) |>
  ptt_plot_add_prediction(ennuste_data, hovertext = list(rounding = 2,
        unit = "(miljoonaa henkilöä)", extra = "(ennuste)"),
        value_multiplier = 0.001) |>
  plotly::layout(
    yaxis = list(range = c(2.2,3))
  ) |>
  ptt_plot_create_widget()
#> Using "tyolliset_ja_tyovoima" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.
# Ei palkansaajoja käytössä # palkansaajat <- ptt_data_robo_l("StatFin/tym/tyti/nj/statfin_tyti_pxt_137l.px") |> # filter( # tiedot == "Palkansaajat, 1000 henkilöä", # time >= "2014-01-01", # toimiala == "Yhteensä" # )

Työttömyys

# työttömyysaste, jolle ennuste
tyottomyysaste <- ptt_data_robo_l("StatFin/tym/tyti/kk/statfin_tyti_pxt_135z.px") |> # työttömyysaste
  filter(
    tiedot == "Työttömyysaste, %, trendi",
    time >= "2014-01-01"
  ) |>
  mutate(tiedot = "Työttömyysaste")
#> \ Requesting get
#> v Requesting get [13ms]
#> 

# tem työttömyysaste, lisäksi tehdään trendimuutos
tem_työttömyysaste <- ptt_data_robo_l("StatFin/tym/tyonv/kk/statfin_tyonv_pxt_12tf.px") |>
    filter(tiedot == "Työttömien työnhakijoiden %-osuus työvoimasta (%)",
           alue == "KOKO MAA",
           time >= "2014-01-01") |>
    mutate(tiedot = "Työttömyysaste (TEM)") |>
    select(tiedot, time, value) |>
    mutate(value = statfitools::trend_series(value, time = time))
#> \ Requesting get
#> v Requesting get [391ms]
#> 

# yhdistetään datasarjat ja plotataan
bind_rows(tyottomyysaste, tem_työttömyysaste) |>
  ptt_plot(
    grouping = tiedot,
    title = "Työttömyysaste",
    subtitle = "%, trendi",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    zeroline = T,
    hovertext =  list(rounding = 1, unit = "%", extra = ""),
    axis_limits = list(y = c(5,15))
  ) |>
  ptt_plot_add_prediction(ennuste_data) |>
  ptt_plot_create_widget()
#> Using "tyottomyysaste" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Lyhyet korot

euribor <-
  ptt_data_robo_l("tidy/euribor") |>
  filter(korko %in% c("12 kk (tod.pv/360)",
                      "12 kk (tod.pv/360)")) |>
  mutate(tieto = "Euribor 12 kk")
#> \ Requesting get
#> v Requesting get [769ms]
#> 

ohjauskorko <-
  ptt_data_robo_l("tidy/ecb_rates") |>
  filter(rate_type == "ECB Main refinancing operations") |>
  mutate(tieto = "Ohjauskorko, EKP")
#> \ Requesting get
#> v Requesting get [377ms]
#> 

bind_rows(euribor, ohjauskorko) |>
  drop_na(value) |>
  arrange(time) |>
  filter(time >= "2008-01-01") |>
  ptt_plot(
    grouping = tieto,
    title = "Lyhyet korot",
    subtitle = "%",
    caption =  "Lähde: Suomen Pankki, Euroopan keskuspankki ja PTT",
    rangeslider = FALSE,
    hovertext = list(rounding = 2),
    zeroline = T
  ) |>
  ptt_plot_add_prediction(
    ennuste_data |>
      mutate(across(is.double, ~.x*100))
  ) |>
  ptt_plot_create_widget()
#> Warning: Predicate functions must be wrapped in `where()`.
#> 
#>   # Bad
#>   data %>% select(is.double)
#> 
#>   # Good
#>   data %>% select(where(is.double))
#> 
#> i Please update your code.
#> This message is displayed once per session.
#> Using "lyhyet_korot" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Pitkät korot

ptt_data_robo_l("tidy/10yield") |>
  drop_na() |>
  filter(time >= "2008-01-01") |>
  select(maa, time, value) |> ## TODO bug in ptt_plot
  ptt_plot(
    grouping = maa,
    title = "Pitkät korot",
    subtitle = "%",
    caption =  "Lähde: Suomen Pankki, Deutche Bundesbank, Fed ja PTT",
    rangeslider = FALSE,
    hovertext = list(rounding = 2),
    zeroline = T
  )  |>
  ptt_plot_add_prediction(
     # tehdään ennustedatan halutuille sarjoille muunnos jotta vastaa maa -sarakkeen maita
     ennuste_data |>
       mutate(sarja_nmi = recode(sarja_nmi,
                                 "10V USA" = "USA",
                                 "10v Saksa" = "Saksa",
                                 "10v Suomi" = "Suomi"
       )),
     value_multiplier = 100
  ) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [411ms]
#> 
#> Using "pitkat_korot" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Raakaöljy

ptt_data_robo("fred/DCOILBRENTEU") |>
  drop_na() |>
  filter(time >= start_time) |>
  mutate(tieto = "Raakaöljy, Brent") |>
  ptt_plot(
    grouping = tieto,
    title = "Raakaöljy",
    subtitle = "$/barreli, Brent",
    caption =  "Lähde: Energy Information Administration ja PTT",
    rangeslider = FALSE,
    hovertext = list(rounding = 2),
    zeroline = T
  ) |>
  ptt_plot_add_prediction(
    ennuste_data
  ) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [623ms]
#> 
#> Using "raakaoljy" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Valuuttakurssi

ptt_data_robo("ecb/EXR", dl_filter = "D.USD.EUR.SP00.A") |>
  drop_na() |>
  filter(time >= "2012-01-01") |>
  mutate(tieto = "Euro/USD") |>
  ptt_plot(
    grouping = tieto,
    title = "Valuuttakurssi",
    subtitle = "Yhdysvaltain dollaria per euro",
    caption =  "Lähde: Euroopan keskuspankki ja PTT",
    rangeslider = FALSE,
    hovertext = list(rounding = 2, unit = "$/€")
  ) |>
  ptt_plot_add_prediction(
    ennuste_data
  ) |>
  ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [84ms]
#> 
#> No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
#> Using "valuuttakurssi" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Kuluttajahintaindeksi

cpi_es <-
  ptt_data_robo("eurostat/prc_hicp_manr", geo_labels = "fi") |>
  filter(
    geo %in% c("Suomi", "EA"),
    coicop == "All-items HICP"
  ) |>
  mutate(geo = recode(geo, EA = "Euroalue")) |>
  select(geo, time, value)
#> \ Requesting get
#> v Requesting get [4s]
#> 

cpi_us <-
  ptt_data_robo("fred/CPIAUCSL", units = "pc1") |>
  mutate(geo = "USA") |>
  select(geo, time, value)
#> \ Requesting get
#> v Requesting get [620ms]
#> 

bind_rows(cpi_es, cpi_us) |>
  filter(time >= start_time) |>
  mutate(geo = fct_relevel(geo, "Suomi", "Euroalue", "USA")) |>
  ptt_plot(
    grouping = geo,
    title = "Kuluttajahinnat",
    subtitle = "%-muutos",
    caption =  "Lähde: Tilastokeskus, Eurostat, BLS ja PTT",
    rangeslider = FALSE,
    hovertext = list(rounding = 1),
    zeroline = T
  ) |>
    ptt_plot_add_prediction(
    filter_recode(ennuste_data,
                  sarja_nmi = c(Suomi = "Inflaatio"))
  ) |> 
  ptt_plot_create_widget() ## |>
#> Using "kuluttajahinnat" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.

Ansiotasoindeksi

Huom. reaalinen ansiotasoindeksi poikkeaa hieman edellisen ennusteen kalvosarjan kuviosta. Tarkista onko deflaattori ja indeksikaava sama. Tässä on käytetty kansallista kuluttajahintaindeksiä.


khi_q <-
  ptt_data_robo("StatFin/hin/khi/kk/statfin_khi_pxt_11xd.px") |>
  filter(
    hyodyke == "0 KULUTTAJAHINTAINDEKSI",
    tiedot == "Pisteluku"
  ) |>
  mutate(time = floor_date(time, "quarter")) |>
  with_groups(time, summarize, khi = mean(value))
#> \ Requesting get
#> v Requesting get [939ms]
#> 

ptt_data_robo("StatFin/pal/ati/nj/statfin_ati_pxt_11zt.px") |>
  inner_join(khi_q, by = "time") |>
  transmute(time, Nimellinen = value, Reaalinen = value/khi) |>
  pivot_longer(c(Nimellinen, Reaalinen), names_to = "tieto")|>
  with_groups(tieto, mutate, value = 100 * (value/lag(value, 4, order_by = time) - 1)) |>
  filter(time >= "2013-01-01") |>
  ptt_plot(
    grouping = tieto,
    title = "Ansiotasoindeksi",
    subtitle = "%, vuosimuutos",
    caption =  "Lähde: Tilastokeskus ja PTT",
    rangeslider = FALSE,
    hovertext = list(rounding = 1),
    zeroline = T
  ) |>
  ptt_plot_create_widget() ## |>
#> \ Requesting get
#> v Requesting get [111ms]
#> 
#> No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
#> Using "ansiotasoindeksi" for htmlwidget filename..
#> No google cloud storage bucket set, no iframe code generated.
## ptt_plot_add_prediction( ## ennuste_data ## )

ptt_plot_upload_widgets()